package com.lsa.skienna.challenge.chap4.the110402_StackOfFlapjack;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.output.ByteArrayOutputStream;

import junit.framework.TestCase;

public class Test_StackOfFlapjack extends TestCase {
	@Override
	protected void setUp() throws Exception {
		 Main.lineSep = IOUtils.LINE_SEPARATOR_UNIX;
	}

	public void testReverse() {
		List<Integer> l = new ArrayList<>(Arrays.asList(1,2,3,4,5,6));
		assertEquals(Arrays.asList(3,2,1,4,5,6), Main.reverse(l, 2));
		
		l = new ArrayList<>(Arrays.asList(1,2,3,4));
		assertEquals(Arrays.asList(4,3,2,1), Main.reverse(l, 3));
		
		l = new ArrayList<>(Arrays.asList(1,2,3,4));
		assertEquals(Arrays.asList(3,2,1,4), Main.reverse(l, 2));
		
		l = new ArrayList<>(Arrays.asList(1,2,3,4,5));
		assertEquals(Arrays.asList(5,4,3,2,1), Main.reverse(l, l.size() - 1));
		
		l = new ArrayList<>(Arrays.asList(1));
		assertEquals(Arrays.asList(1), Main.reverse(l, l.size() - 1));
		
		l = new ArrayList<>(Arrays.asList(1,2));
		assertEquals(Arrays.asList(2,1), Main.reverse(l, l.size() - 1));
	}
	
	public void testStackOfFlapjack() throws IOException {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        Main.process(new FileInputStream("data/pc4/the110402_StackOfFlapjack/110402.inp"), new PrintStream(out));
        String expected = FileUtils.readFileToString(new File("data/pc4/the110402_StackOfFlapjack/110402.oup"));
        assertEquals(expected, out.toString());
    }
    
}
